﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StateTheater.Interfaces;
using Castle.MonoRail.Framework;

namespace StateTheater.Controllers
{
    public class QuoteItem : IQuote
    {
        #region IQuote Members
        public string Speaker { get; set; }
        public string Quote { get; set; }
        #endregion
    }
    public class QuoteController : SmartDispatcherController
    {
        Random rnd = new Random();
        List<QuoteItem> _quoteList = null;

        public QuoteItem NewQuote()
        {
            int skip = rnd.Next(this.QuoteList.Count);
            return _quoteList[skip];
        }

        private List<QuoteItem> QuoteList
        {
            get
            {
                if (_quoteList == null)
                {
                    // retrieve from cache
                }

                if (_quoteList == null)
                {
                    StateTheaterDataContext db = new StateTheaterDataContext();
                    _quoteList = (from qu in db.Quotes
                    select new QuoteItem 
                           {
                               Speaker = qu.Speaker,
                               Quote = qu.Quote
                           }).ToList();
                }

                return _quoteList ?? new List<QuoteItem>();
            }
        }
    }
}
